CROSS_COMPILE ?= arm-none-eabi-
CC := $(CROSS_COMPILE)gcc


INC_PATH = -Iinc\
           -I os/inc \
LIB_PATH =  -lc \
           -lm  \
           -lnosy \


CFLAGS = -fno-common -g -Og \
	  -fno-builtin  \
	 -mcpu=cortex-m4 -mthumb \
	 -mfpu=fpv4-sp-d16   -mfloat-abi=hard \
	 -specs=nano.specs \
	 -fdata-sections -ffunction-sections  \
	 -Wl,--gc-sections \
	 -T STM32L475VETx_FLASH.ld \
         $(LIB_PATH)  \
         $(INC_PATH)   \

INC_PATH = -Iinc\
           -I os/inc \
           

TARGET = initcalls
all: $(TARGET)

SRC= startup.c main.c systick.c tim.c \
	os/initcalls.c


$(TARGET): $(SRC)
	$(CC) $^  $(CFLAGS)  -o $@.elf
	$(CROSS_COMPILE)objcopy -Obinary $@.elf $@.bin
	$(CROSS_COMPILE)objdump -S $@.elf > $@.list

qemu: $(TARGET)
	@qemu-system-arm -M ? | grep stm32-p103 >/dev/null || exit
	@echo "Press Ctrl-A and then X to exit QEMU"
	@echo
	qemu-system-arm -M stm32-p103 -nographic -kernel hello.bin

clean:
	rm -f *.o *.bin *.elf *.list
